<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>登录-注册</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <link rel="stylesheet" href="css/init.css" />
    <script type="text/javascript" src="js/static.js"></script>
    <link rel="stylesheet" type="text/css" href="css/layui.css" />
    <style type="text/css">
    body {
        background-color: #eeeeee;
        background: url(images/bg.png) no-repeat 0 0;
        background-size: 100% 100%;
        height: 100vh;
    }
    </style>
</head>

<body>
    <div class="main">
        <div class="login layui-anim layui-anim-up">
            <div class="message">智能电摩 管理登录</div>
            <div id="darkbannerwrap"></div>
            <input class="username" name="public_bike_project_user_name" lay-verify="required" placeholder="手机号" type="text">
            <hr class="hr10">
            <input name="public_bike_project_user_pwd" placeholder="密码" lay-verify="required" type="password" class="layui-input pwdInput">
            <hr class="hr10">
            <input name="phone_code" lay-verify="required" placeholder="手机验证码" type="text" class="layui-input codeInput">
            <hr class="hr10">
            <div style="width:100%" codeId=""  class="layui-btn get_code_btn layui-btn-normal " onclick="get_code()">发送短信验证码(每60s一次)</div>
            <hr class="hr10">
            <div onclick="loginForm()" class="layui-btn layui-btn-lg layui-btn-fluid">登录</div>
            <hr class="hr10">
            <div class="layui-btn layui-btn-danger forget" style="width:48%;">忘记密码</div>
            <div class="layui-btn layui-btn-normal CodeStatus" style="float:right;width:48%;">验证码登录</div>
            <div class="layui-btn layui-btn-normal pwdStatus" style="float:rig ht;width:48%;">密码登录</div>
        </div>
        <div class="code login layui-anim layui-anim-up">
            <div class="message">智能电摩 密码找回</div>
            <div id="darkbannerwrap"></div>
            <form method="post" class="layui-form">
                <input name="username" placeholder="手机号" type="text" lay-verify="required" class="layui-input ">
                <hr class="hr10">
                <input name="phone_code" lay-verify="required" placeholder="手机验证码" type="text" class="layui-input">
                <hr class="hr15">
                <div style="width:100%" class="layui-btn  get_code_btn layui-btn-normal" onclick="get_code()">发送短信验证码(每60s一次)</div>
                <hr class="hr10">
                <input name="password" lay-verify="required" placeholder="新密码" type="password" class="layui-input">
                <hr class="hr10">
                <input name="password" lay-verify="required" placeholder="确认密码" type="password" class="layui-input">
                <hr class="hr10">
                <input value="确定" lay-submit lay-filter="login" style="width:100%;" type="submit">
                <hr class="hr10">
            </form>
        </div>
    </div>
</body>
<script type="text/javascript" src="layui/layui.all.js"></script>
<script type="text/javascript">
 
$(".code").hide();
$(".forget").click(function() {
    $(".code").show();
});
$(".pwdStatus,.codeInput,.get_code_btn").hide();
$(".CodeStatus").click(function(event) {
    $(".pwdStatus,.codeInput,.get_code_btn").toggle();
    $(".CodeStatus,.pwdInput").toggle(false);
});
$(".pwdStatus").click(function(event) {
    $(".pwdStatus,.codeInput,.get_code_btn").toggle(false);
    $(".CodeStatus,.pwdInput").toggle();
});

function loginForm() {
    var phone=$(".username").val();
    var pwd = $(".pwdInput").val();
    var code = $(".codeInput").val();
    var codeId = $(".get_code_btn").attr("codeId");
    if (!phone) {
        layer.msg("请填写完整")
        return false;
    }
    var form = new FormData();
    form.append("phone", phone);
    form.append("password", pwd);
    form.append("codeId", codeId)
    form.append("code", code)

    $.ajax({
        type: "POST",
        url: preUrl + "/a/sys/adminLogin",
        processData: false,
        contentType: false,
        data: form,
        success: function(res) {
            layer.msg(res.msg);
            if (res.suc) {
                setSession("if", JSON.stringify(res.result));
                setCookie("p", res.result.phone);
                window.location = "index.html";
            } else {
                layer.msg(res.msg);
            }
        },
        error: function() {

        }
    })





}







var countdown = 60;
//构造一个倒计时函数叫settime
function regForm(obj) {
    var phone = $(".regPhone").val();
    var pwd = $(".regPwd").val();
    var code = $(".vertifyCode").val()
    if (!phone) {
        layer.msg("请输入手机号")
        return false;
    }
    settime(obj);
    sendCode(phone);



}





function settime(obj) {
    //开始判断倒计时是否为0

    if (countdown == 0) {
        obj.removeAttribute("disabled");
        $(obj).html("获取验证码");
        countdown = 60;
        //立即跳出settime函数，不再执行函数后边的步骤
        return;
    } else {
        obj.setAttribute("disabled", true);
        $(obj).html("重新发送(" + countdown + ")");
        countdown--;
    }
    //过1秒后执行倒计时函数
    setTimeout(function() { settime(obj) }, 1000)
}

$(function() {
    if (getCookie("token")) {
        window.location.href = "home.html";
    }
})

var countdown = 60;
var btn_disable = false;
var phone_code = '';

function get_code() {

    if (btn_disable) {
        return false;
    } else {
        var phone = $('.username').val();
        if (!phone) {
            layer.alert("手机号不能为空!", { icon: 5 });
            return false;
        }


        $('.get_code_btn').addClass('layui-btn-disabled');
        btn_disable = true;
        run_time();
    }

    $.ajax({
        async: false,
        url: preUrl + "/m/sms/sendadminlogin",
        type: "POST",
        data: {
            phone: phone
        },
        success: function(res) {
            layer.msg(res.msg)
            if (res.suc){
                $(".get_code_btn").attr("codeId",res.result);
            }else{

            }

        }
    });
}

function check_code() {


}

function run_time() {
    var btn_obj = $('.get_code_btn');

    if (countdown === 0) {
        btn_obj.removeClass('layui-btn-disabled');
        btn_obj.text("发送短信验证码(每60s一次)");
        btn_disable = false;
        countdown = 60;
        return false;
    } else {
        btn_obj.text("距离可以重新发送, 还剩 " + countdown + " 秒");
        countdown--;
    }
    setTimeout(function() {
        run_time();
    }, 1000);
}
</script>

</html>